package dataCollection;

import java.util.Collections;
import java.util.Random;
import java.util.Vector;

import dataCollection.Card.Suit;
import dataCollection.Card.Value;
/**
 * 
 * @author Andrej Fast
 *
 * Deck of 54 Cards including all cards from two to king and ace of each suite and two jokers
 * 
 */
public class CardDeck {
  protected Vector<Card> cards_;
  protected Random random_gen_;
  protected int first_card_;
  private final int deck_size_ = 54;
  
  public CardDeck() {
    cards_ = new Vector<Card>(deck_size_);
    random_gen_ = new Random();
    first_card_ = 0;

    for(Suit s : Suit.values()) {
      // We do not create Jokers for each suit, i.e. length - 1
      for(int i = 0; i < Value.values().length-1; i++) {
        Value v = Value.values()[i];
        Card card = new Card(s, v);
        cards_.add(card);
      }
    }
    // Hearts represents one red card, Spades one black card
    Card joker_red   = new Card(Suit.HEARTS, Value.JOKER);
    Card joker_black = new Card(Suit.SPADES, Value.JOKER);
    cards_.add(joker_red);
    cards_.add(joker_black);
  }
  
  public void shuffle() {
    Collections.shuffle(cards_);
    cards_.add(4, new Card(Suit.CLUBS, Value.EIGHT));
    first_card_ = 0;
  }
  
  public Card takeUpcard() {
    Card upcard = cards_.elementAt(first_card_++);
    first_card_ = first_card_ % deck_size_;
    return upcard;
  }
  
  public Card takeRandomCard() {
    Card card = cards_.elementAt(random_gen_.nextInt() % deck_size_);
    return card;
  }
}
